using ThirdLife.UI.WinForms.Controls;

namespace ThirdLife.UI.WinForms.Modules
{
  public class ChatAreaUIModule : IUIModule
  {
    private TLChatArea _chatArea;
    private IUIModuleServices _moduleServices;

    #region IUIModule Members

    public IUIModuleServices ModuleServices
    {
      get { return _moduleServices; }
      set { _moduleServices = value; }
    }

    public string Name
    {
      get { return "ThirdLife_ChatArea"; }
    }

    public void Setup()
    {
      _chatArea = new TLChatArea(this);
      ModuleServices.Startup.ApplicationStarted += Startup_ApplicationStarted;
      ModuleServices.Communication.ChatRecieved += new ChatReceivedHandler(Communication_ChatRecieved);
      ModuleServices.Communication.SelfChatRecieved += new ChatReceivedHandler(Communication_SelfChatRecieved);
    }

    void Communication_SelfChatRecieved(string fromName, string message)
    {
      _chatArea.AddNewMessageFromAvatar(fromName, message);
    }

    void Communication_ChatRecieved(string fromName, string message)
    {
      _chatArea.AddNewMessageFromAvatar(fromName, message);
    }

    #endregion

    private void Startup_ApplicationStarted()
    {
      ModuleServices.Registration.AddToMainScreen(_chatArea, new DockLocation(_chatArea.Height, 3, true));
    }
  }
}